<?php
/* -------------------------------------------------------------------------------------
* 	ID:						$Id: account_history.php 438 2014-01-19 11:50:30Z phone.mueller@googlemail.com $
* 	Letzter Stand:			$Revision: 438 $
* 	zuletzt geaendert von:	$Author: siekiera $
* 	Datum:					$Date: 2014-01-19 11:50:30 +0000 (Sun, 19 Jan 2014) $
*
* 	SEO:mercari by Siekiera Media
* 	http://www.seo-mercari.de
*
* 	Copyright (c) since 2011 SEO:mercari
* --------------------------------------------------------------------------------------
* 	based on:
* 	(c) 2000-2001 The Exchange Project  (earlier name of osCommerce)
* 	(c) 2002-2003 osCommerce - www.oscommerce.com
* 	(c) 2003     nextcommerce - www.nextcommerce.org
* 	(c) 2005     xt:Commerce - www.xt-commerce.com
*
* 	Released under the GNU General Public License
* ----------------------------------------------------------------------------------- */
define('GLOBAL_COLUMN_LEFT', '0');
include ('includes/application_top.php');
$module_smarty = new Smarty;
require (DIR_FS_CATALOG.'templates/'.CURRENT_TEMPLATE.'/source/boxes.php');
require_once (DIR_FS_INC.'inc.count_customer_orders.php');
require_once (DIR_FS_INC.'inc.date_long.php');
require_once (DIR_FS_INC.'inc.image_button.php');
require_once (DIR_FS_INC.'inc.get_all_get_params.php');
require_once (DIR_FS_INC.'inc.build_order_id.php');

if (!isset ($_SESSION['customer_id']))
	redirect(href_link(FILENAME_LOGIN, '', 'SSL'));

$breadcrumb->add(NAVBAR_TITLE_1_ACCOUNT_HISTORY, href_link(FILENAME_ACCOUNT, '', 'SSL'));
$breadcrumb->add(NAVBAR_TITLE_2_ACCOUNT_HISTORY, href_link(FILENAME_ACCOUNT_HISTORY, '', 'SSL'));

require (DIR_WS_INCLUDES.'header.php');

$module_content = array();
if (($orders_total = count_customer_orders()) > 0) {
	$listing_sql = "SELECT 
						o.orders_id, 
						o.date_purchased, 
						o.delivery_name, 
						o.billing_name, 
						ot.text AS order_total, 
						s.orders_status_name 
					FROM 
						".TABLE_ORDERS." o, 
						".TABLE_ORDERS_TOTAL." ot, 
						".TABLE_ORDERS_STATUS." s 
					WHERE 
						o.customers_id = '".(int) $_SESSION['customer_id']."' 
					AND 
						o.orders_id = ot.orders_id 
					AND 
						ot.class = 'ot_total' 
					AND 
						o.orders_status = s.orders_status_id 
					AND 
						s.language_id = '".(int) $_SESSION['languages_id']."' 
					ORDER BY 
						orders_id DESC";
						
	$listing = new page_break($listing_sql, $_GET['page'], true, 'account_history.php');

	while (!$listing->sql_string->EOF) {
		$products = $db->db_query("SELECT COUNT(*) AS count FROM ".TABLE_ORDERS_PRODUCTS." WHERE orders_id = '".$listing->sql_string->fields['orders_id']."'");

		if (not_null($listing->sql_string->fields['delivery_name'])) {
			$order_type = TEXT_ORDER_SHIPPED_TO;
			$order_name = $listing->sql_string->fields['delivery_name'];
		} else {
			$order_type = TEXT_ORDER_BILLED_TO;
			$order_name = $listing->sql_string->fields['billing_name'];
		}
		$module_content[] = array (	'ORDER_ID' => build_order_id($listing->sql_string->fields['date_purchased'], $listing->sql_string->fields['orders_id'], 'confirm'), 
									'ORDER_STATUS' => $listing->sql_string->fields['orders_status_name'], 
									'ORDER_DATE' => date_long($listing->sql_string->fields['date_purchased']), 
									'ORDER_PRODUCTS' => $products->fields['count'], 
									'ORDER_TOTAL' => strip_tags($listing->sql_string->fields['order_total']), 
									'ORDER_BUTTON' => '<a href="'.href_link(FILENAME_ACCOUNT_HISTORY_INFO, 'page='.(empty($_GET['page']) ? "1" : (int)$_GET['page']) .'&order_id='.$listing->sql_string->fields['orders_id'], 'SSL').'">'.image_button('small_view.gif', SMALL_IMAGE_BUTTON_VIEW).'</a>');
		$listing->sql_string->MoveNext();
	}
	
	$module_smarty->assign('order_content', $module_content);
}

$module_smarty->assign('language', $_SESSION['language']);
$module_smarty->assign('BUTTON_BACK', '<a href="'.href_link(FILENAME_ACCOUNT, '', 'SSL').'">'.image_button('button_back.gif', IMAGE_BUTTON_BACK).'</a>');
$module_smarty->caching = false;
$main_content = $module_smarty->fetch(CURRENT_TEMPLATE.'/module/account_history.html');

$smarty->assign('language', $_SESSION['language']);
$smarty->assign('main_content', $main_content);
$smarty->caching = false;
if (!defined('RM'))
	$smarty->loadFilter('output', 'note');
$smarty->loadFilter('output','trimwhitespace');
$smarty->display(CURRENT_TEMPLATE.'/index.html');
include ('includes/application_bottom.php');
?>